package com.googlecode.restfulspringmvc.web.annotation;

import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;

import javax.servlet.http.HttpServletRequest;

@Controller
public class MultiActionSampleController {
    @RequestMapping(value = "/store/artifacts/{:projectname}/{:timestamp}", method = RequestMethod.GET)
    public ModelMap artifacts(@RequestParam("projectname") final String projectname,
                              @RequestParam("timestamp") final long timestamp) {
        return new ModelMap() {
            {
                addAttribute("projectname", projectname);
                addAttribute("timestamp", timestamp);
            }
        };

    }

    @RequestMapping(value = {"/store/logs/{:projectname}/{:timestamp}", "/save/logs/{:projectname}/{:timestamp}"},
            method = RequestMethod.GET)
    public ModelMap logs(@RequestParam("projectname") final String projectname,
                         @RequestParam("timestamp") final long timestamp, final HttpServletRequest request) {
        return new ModelMap() {
            {
                addAttribute("projectname", projectname);
                addAttribute("timestamp", timestamp);
                addAttribute("file", request.getParameter("file"));
            }
        };

    }
}
